#include "EString.h"
#include <iostream>
#include <vector>
#include <map>
#include <DefineCommon.h>

int main_test_EString(int argc, const char *argv[])//_test_EString
{
    EString str1("Hello World!");
    EString str2;

    ELOG_INFO("Test EString.data():\n%s", str1.data());

    ELOG_INFO("Test EString.size():\n%d", str1.size());

    str1.append("Hello");
    ELOG_INFO("Test EString.append(const char*):\n%s", str1.data());

    str1.append(EString(" World!"));
    ELOG_INFO("Test EString.append(const EString&):\n%s", str1.data());

    // str1.insert(0, '-');
    // ELOG_INFO("Test EString.insert(size_t, char):\n%s", str1.data());
    str1.insert(12, '-');
    ELOG_INFO("Test EString.insert(size_t, char):\n%s", str1.data());

    str1.insert(12, "-");
    ELOG_INFO("Test EString.insert(size_t, const char* ):\n%s", str1.data());

    str1.erase(12, 2);
    ELOG_INFO("Test EString.erase(size_t, size_t):\n%s", str1.data());

    str1.replace("!", "!*");
    ELOG_INFO("Test replace(const char*, const char*):\n%s", str1.data());

    // EString str4("/*class member functions*/\n#EItemName#_MemberFun_#MemberFunName#");
    // str4.replace("#EItemName#", "EItemInPlugin");
    // str4.replace("#MemberFunName#", "ui_testAdd");
    // ELOG_INFO("Test replace(const char*, const char*):\n%s", str4.data());


    const char* tempChar = R"(
/**class member functions*/
class #EItemName#_MemberFun_#MemberFunName# : public EItemMetaFunction
    )";

    EString str4 = tempChar;
    str4.replace("#EItemName#", "EItemInPlugin");
    str4.replace("#MemberFunName#", "ui_testAdd");
    ELOG_INFO("Test replace(const char*, const char*):\n%s", str4.data());

    // const char* tempChar = R"(
    // abc
    // def   ddeurjt8990087763
    // )";
    // str4 = tempChar;
    // str4.replace("abc", "123");
    // str4.replace("def", "456");
    // ELOG_INFO("Test replace(const char*, const char*):\n%s", str4.data());

    str1.remove("*");
    ELOG_INFO("Test remove(const char*):\n%s", str1.data());

    ELOG_INFO("Test subStr(size_t, size_t):\n%s", str1.subStr(12, 12).data());

    ELOG_INFO("Test left(size_t):\n%s input=12", str1.left(12).data());

    ELOG_INFO("Test right(size_t):\n%s", str1.right(12).data());

    ELOG_INFO("Test right(size_t):\n%s", str1.right(1).data());

    ELOG_INFO("Test find(char, size_t) const:\n%d", str1.find('!', 2));

    ELOG_INFO("Test find(const char*, size_t) const:\n%d", str1.find("!", 2));

    ELOG_INFO("Test find(const EString&, size_t) const:\n%d", str1.find(EString("!"), 2));

    ELOG_INFO("Test contains(const char*):\n%s", EString::boolValue(str1.contains("World")).data() );

    ELOG_INFO("Test contains(const char*):\n%s", EString::boolValue(str1.contains("Worle")).data() );

    ELOG_INFO("Test isEmpty():\n%s", EString::boolValue(str1.isEmpty()).data() );

    ELOG_INFO("Test isEmpty():\n%s", EString::boolValue(str2.isEmpty()).data() );

    str2 = str1;
    ELOG_INFO("Test operator=(const EString& ):\n%s", str2.data());

    str2 = "Hello";
    ELOG_INFO("Test operator=(const EString& ):\n%s", str2.data());

    str2 += " Wo";
    ELOG_INFO("Test operator+=(const char* ):\n%s", str2.data());

    str2 += EString("rld");
    ELOG_INFO("Test operator+=(const EString& ):\n%s", str2.data());

    str2 += '!';
    ELOG_INFO("Test operator+=(char ):\n%s", str2.data());

    ELOG_INFO("Test operator+(const char* ):\n%s", (str2 + "Hello").data());

    ELOG_INFO("Test operator+(const EString& ):\n%s", (str2 + EString(" World")).data());

    ELOG_INFO("Test operator+(char ):\n%s", (str2 + '!').data());

    ELOG_INFO("Test operator[](size_t ):\n%c", str2[11]);

    ELOG_INFO("Test operator<(const EString&):\n%s", EString::boolValue(str2<"Abc").data());

    ELOG_INFO("Test operator<(const EString&):\n%s", EString::boolValue(str2<"IAAA").data());

    ELOG_INFO("Test operator>(const EString&):\n%s", EString::boolValue(str2>"Abc").data());

    ELOG_INFO("Test operator>(const EString&):\n%s", EString::boolValue(str2>"IAAA").data());

    ELOG_INFO("Test operator==(const EString&):\n%s", EString::boolValue(str2=="Hello World!").data());

    ELOG_INFO("Test operator==(const EString&):\n%s", EString::boolValue(str2=="Hello World!AAA").data());

    ELOG_INFO("Test number(int):\n%s", EString::number(123).data());

    ELOG_INFO("Test number(double, const char*):\n%s", EString::number(123.45678, "%5.2f").data());

    ELOG_INFO("Test boolVlaue(bool):\n%s", EString::boolValue(true).data());

    EStringList strList;
    strList.push_back(str1);
    strList.push_back(str2);
    strList.push_back("Hello World!");

    ELOG_INFO("Test EStringListContains():\n%s", EString::boolValue(
                EString::EStringListContains(strList, "Hello")).data()
            );

    strList = str1.split("!");
    ELOG_INFO("Test split():\n%s", 
            EString::EStringListGetPrintStr(strList).data()
            );

    strList = str1.split("@");
    ELOG_INFO("Test split():\n%s", 
            EString::EStringListGetPrintStr(strList).data()
            );

    EString str3 = "/root/EEditor2/source/LibCommon;/root/EEditor2/source/PluginDefault";
    strList = str3.split(";");
    ELOG_INFO("Test split():\n%s", 
            EString::EStringListGetPrintStr(strList).data()
            );
    

    EMap<EString, int> mapTest;
    mapTest[str1] = 0;
    mapTest[str2] = 1;

    ELOG_INFO("Test EMap<EString,int>:\n");
    for(EMap<EString, int>::iterator it=mapTest.begin(); it != mapTest.end(); it++)
    {
        ELOG_INFO("key=%s,value=%d", it->first.data(), it->second);
    }
    
    return 0;
}
